package android.TaskApp;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class usergroupActivity extends Activity
{
	private int[] usergroupids = new int[3];
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	   setContentView(R.layout.usergroups);
	   
		Button homegroupButton;
	    Button officegroupButton;
	    Button generalgroupButton; 
	        
	    homegroupButton = (Button) findViewById(R.id.homegroup_button);
	    officegroupButton = (Button) findViewById(R.id.officegroup_button);
		generalgroupButton = (Button) findViewById(R.id.generalgroup_button);
		
		getUserGroupIds();
		
		homegroupButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				startActivity(new Intent(usergroupActivity.this,ViewTasksActivity.class));				
			}
			});
		
		officegroupButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				
			}
			});
		
		generalgroupButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				
			}
			});
				
	}

	private void getUserGroupIds()
	{
		SharedPreferences prefs= PreferenceManager.getDefaultSharedPreferences(this);
		int userid = prefs.getInt("userid",0);
		UserGroupResponse groups= WebServiceHelper.getUserGroups(userid);
		if (groups.getStatusCode()>0)
		{
			UserGroupVO[] usergroups = groups.getUsergroups();
			for(int i = 0 ; i< usergroups.length; i++)
			{
				if(usergroups[i].getGroupname().toLowerCase().equals("home"))
				{
					usergroupids[0] = usergroups[i].getUsergroupid();
				   SharedPreferences.Editor edit= prefs.edit();
				   edit.putInt("homegroupid", usergroupids[0]);
				   edit.commit();
				}
				if(usergroups[i].getGroupname().toLowerCase().equals("office"))
				{
					usergroupids[1] = usergroups[i].getUsergroupid();
									
				}
				if(usergroups[i].getGroupname().toLowerCase().equals("general"))
				{
					usergroupids[2] = usergroups[i].getUsergroupid();
				}
			}
			
		}
		
	}

}
